<template>
  <div class="layout-all">
    <control :config="config" />

    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        highlight-current-row
        style="width: 100%;margin-top:50px"
      >
      <el-table-column align="center" prop="id" label="序号" width="70" :fixed="isMobile()?'left':undefined"/>
      <el-table-column align="center" prop="status" label="平台" width="80">
          <template slot-scope="scope">
            {{scope.row.shop_id>0?scope.row.title:'后台'}}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="name" label="调用者"  width="100"/>
        <el-table-column align="center" prop="type" label="类型" width="80">
          <template slot-scope="scope">
            <el-tag :type="type_list[scope.row.type]">{{scope.row.type_str}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="url" label="路径"  width="200"/>

        <el-table-column align="center" prop="content" label="内容" show-overflow-tooltip/>
        <el-table-column align="center" prop="ip" label="ip" width="150" />
        <el-table-column align="center" prop="useragent" label="UA" width="200" show-overflow-tooltip/>
        <el-table-column align="center" prop="create_time" label="修改时间" width="160" />
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import control from '../../components/control/control'
export default {
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入账号或平台', field: 'title', val: '' },
        {
          type: "select",
          placeholder: "请选择类型",
          field: "type",
          val: "",
          options: [],
        },
        {
          type: "select",
          placeholder: "请选择平台",
          field: "shop_id",
          val: "",
          options: [
            {value:1,label:'后台'},
            {value:2,label:'店铺'},
          ],
        },
      ],
      value: '',
      searchWhere: {
        title: ''
      },
      tableData: [],
      type_list: ['primary','success','warning','danger','info'],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },

  created() {
    this.onSearch()
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      this.get('/admin/SaveLog/index', form, 'POST').then(e => {
        this.tableData = e.list.data
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.current_page = e.list.current_page
        this.config[1].options=e.type_arr
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 删除
    onDel(id) {
      this.$msg_confirm().then(e => {
        if (e) {
          this.get('/admin/SaveLog/del?id=' + id, this.form, 'POST').then(e => {
            this.onSearch()
          })
        }
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
